The invention relates generally to software applications and, more particularly, to methods and apparatus for managing resource usage in an object-based system.
In the consumer field, there is intense pressure to keep costs down. Thus, the capabilities of memory and CPU devices within consumer systems, for example, are scaled down as much as possible to minimize overall costs. For example, cable television set top boxes typically include limited memory space and CPU capabilities. As object-based systems are integrated within consumer devices, it is becoming more important to manage resource usage effectively within the object-based systems. In other words, as a result of limited resources (among other reasons), a major issue within the object-oriented field is how to track and manage resource usage.
It is especially important to track resource usage of untrusted code. For example, it is important to track the resource usage of an applet that is downloaded from an untrusted URL into a set top box. The downloaded applet may be maliciously or unintentionally designed to consume an inordinate amount of resources, such as memory space or CPU time.
It is also important to track and manage resource usage of sets of related code. For example, the threads executed on behalf of an applet may together or individually consume too much of a limited resource of the set top box. Thus, it is not enough to simply track and manage the resource usage of individual threads. For example, an applet may initiate multiple threads that work together to consume resources. Tracking resource usage of individual threads only allows one to kill an individual thread. However, prior to killing a resource consuming thread, an applet may launch another resource consuming thread.
Accordingly, there is a need for improved methods and apparatus for tracking and managing resource usage. Additionally, there is a need for mechanisms for tracking and managing resource usage for sets of related code. Several mechanisms for managing resources are described in the above referenced co-pending U.S. patent application Ser. No. 09/394,118. Specifically, a resource context structure (herein referred to as a xe2x80x9clogical Virtual Machine or logical VMxe2x80x9d) is created and updated for each set of codes that can share the same objects. The logical VM generally provides a mechanism for referencing the codes from one or more computer programs that can share the same resource or object. Thus, the code of any currently executing thread will be associated with a particular logical VM. Associating threads with a particular logical VM allows the related threads to be terminated together when they start to misbehave (e.g., by causing a denial of service attack).
However, currently there is also a need for mechanisms to allow code in different logical VM""s to communicate with each other. More specifically, there is a need for communication between a first and a second logical VM without inhibiting a termination procedure from being performed on code associated with the terminating logical VM and/or without adversely affecting execution of code of the non-terminating logical VM. Additionally, there is a need for mechanisms that allow termination of code associated with a first logical VM without requiring any cooperation from the terminating code of the first logical VM or from any other code of a second logical VM.
Broadly speaking, the present invention fills these needs by providing apparatus and methods for a set of related code to communicate with another set of related code. Preferably, such communication does not inhibit termination of any threads from either set of related code. Additionally, it is preferred that execution of the non-terminating related code set is not detrimentally affected by the termination of the other related code set.
In one embodiment, a method for executing a remote method is disclosed. Each argument of a remote method is either wrapped or copied. Arguments that are remote objects (e.g., instances of classes that are declared as xe2x80x9cremotexe2x80x9d) are wrapped, whereas other arguments are copied. When a method is invoked on such a wrapped remote object, it is executed as a remote method. Preferably, an argument that is a remote object is wrapped by generating a stub class for the argument, where an instance of the stub class references the argument.
The remote method is invoked using the wrapped or copied argument(s) (e.g., an instance of a stub class for each of the arguments are used by the invoked method). A result of the remote method is then wrapped (e.g., prior to being used by the process that has invoked the remote method) when the result is a remote object. In contrast, the result of the remote method is simply copied (e.g., prior to being used by the process that is receiving and using the result) when the result is not a remote object.
In one implementation, the result is only wrapped or copied when an invocation thread associated with invoking the remote method is not being terminated. Otherwise, an exception is thrown on the remote method when the invocation thread is terminated.
In one aspect, wrapping the argument or the result generally includes creating a wrapper object for the argument or the result and remembering an association between the wrapper object and the argument or the result when a wrapper object has not already been created. In this aspect, wrapping also includes finding the wrapper object for the argument or the result based on a previous association between the argument or the result and the wrapper object when the wrapper object has already been created. In a specific implementation creating the wrapper object for the argument or the result includes finding or generating a remote stub class, creating an instantiation of the remote stub class, and setting a data member within the remote stub class to refer to the argument or the result.
In a further implementation, generating the remote stub class includes generating a class name, adding a method implementation for each method of a class of the argument or result being wrapped into a class definition array, and remembering an association between the class and the remote stub class. In yet another further implementation, finding the remote stub class is based on a previously remembered association between a class of the object being wrapped and the remote stub class.
In another aspect, copying each argument or result includes serializing each argument or result into a byte array when the argument or result implements serialization. The serialized argument or result is then deserialized by the code that will use the copy (e.g., the Logical VM that receives the copy) with respect to a target class loader associated with such code. Preferably, copying each argument or result also includes implementing a failure process when the each argument or the result does not implement serialization.
In another embodiment, the invention pertains to a computer readable medium containing computer codes for executing a remote method. The computer readable medium includes computer code for performing one or more of the above described method embodiments.
These and other advantages of the present invention will become apparent upon reading the following detailed descriptions and studying the various figures of the drawings.